#ifndef __CK_VALUE_H__
#define __CK_VALUE_H__

#include "ckObject.h"
#include "zCore.h"

namespace ck
{
	typedef enum ckValueType
	{
		ckValueTypeUnknown = 0,
		ckValueTypeBool,
		ckValueTypeChar,
		ckValueTypeShort,
		ckValueTypeInt,
		ckValueTypeLong,
		ckValueTypeInt64,
		ckValueTypeFloat,
		ckValueTypeDouble,
		ckValueTypeNumeric,
		ckValueTypeString,
		ckValueTypeDate,
		ckValueTypeTime,
		ckValueTypeDateTime,
		ckValueTypeBLOB,
		ckValueTypeGeometry,
		ckValueTypeNull,
	} ckValueType;

	class ZCORE_API Value :	public ckObject
	{
	public:
		Value();
		Value(ckValueType vt);
		Value(bool    val);
		Value(char    val);
		Value(short   val);
		Value(int     val);
		Value(long    val);
		Value(z_int64 val);
		Value(float   val);
		Value(double  val);
		Value(const char* val);
		Value(ck_date_t* val);
		Value(ck_time_t* val);
		Value(ck_datetime_t* val);
		//Value(const TIME_STRU* val);
		//Value(const Geometry*  val);
		Value(const Value& other);
		Value(const Value* other);
		virtual ~Value();

	public:
		ckValueType		GetType() const;
		void			Clear();
		bool			IsNull() const;
		void			SetType(ckValueType vt);
		bool			GetBool()		const;
		char			GetChar()		const;
		short			GetShort()		const;
		int				GetInt()		const;
		long			GetLong()		const;
		float			GetFloat()		const;
		double			GetDouble()		const;
		z_int64			GetInt64()		const;
		const char*		GetString()		const;
		const ck_date_t*		GetDate()		const;
		const ck_time_t*		GetTime()		const;
		const ck_datetime_t*	GetDateTime()	const;
		//const TIME_STRU*GetTime()		const;
		//const Geometry*	GetGeometry()	const;
		//AgString*		GetString();
		const char*		GetString();
		//TIME_STRU*		GetTime();
		//Geometry*		GetGeometry();
		long			SetBool(bool val);
		long			SetChar(char val);
		long			SetShort(short val);
		long			SetInt(int val);
		long			SetLong(long val);
		long			SetFloat(float val);
		long			SetDouble(double val);
		long			SetInt64(z_int64 val);
		long			SetString(const char* val, bool copy = false);
		//long			SetTime(TIME_STRU* val, bool copy = false);
		//long			SetGeometry(Geometry*  val, bool copy = false);
		long			SetValue(const Value& rValue);
		long			SetValue(const Value* rValue);
		//bool			Equals(const Value* pValue) const;
		//bool			Equals(const Value& rValue) const;

		long			GetAsString(char* szstr, size_t size);
			
		void            SetModified(bool modified);
		bool            IsModified() const;

	public: // operator functions
		Value& operator=(const Value& other);
		Value& operator=(bool val);
		Value& operator=(char val);
		Value& operator=(short val);
		Value& operator=(int val);
		Value& operator=(long val);
		Value& operator=(z_int64 val);
		Value& operator=(float val);
		Value& operator=(double val);

		Value& operator=(const char* val); //LiuDL

		//Value& operator=(const TIME_STRU* val);
		//Value& operator=(const Geometry* val);

		//Value& operator=(TIME_STRU* val);
		//Value& operator=(Geometry* val);

		// Literal comparison. Types and values must match.
		bool	operator==(const Value& other) const;
		bool	operator!=(const Value& other) const;
		bool	operator< (const Value& other) const;
		bool	operator<=(const Value& other) const;
		bool	operator> (const Value& other) const;
		bool	operator>=(const Value& other) const;

		operator char* () const;
		operator bool() const;
		operator char() const;
		operator int() const;
		operator z_int64 () const;
		operator float() const;
		operator double() const;

	private:
		typedef struct  tagVARIANT_STRU
		{
			short vt;
			union
			{
				char       chrVal;
				bool       blrVal;
				short      shtVal;
				int        intVal;
				long       lngVal;
				z_int64	   i64Val;

				float      fltVal;
				double     dblVal;

				char*	   strVal;
				//TIME_STRU* timVal;

				ck_date_t	datVal;
				ck_time_t	timVal;
				ck_datetime_t dtmVal;
			};
			bool m_isModified;
		} VARIANT_STRU;
	private:
		void InitVariant(VARIANT_STRU& val);
	private:
		VARIANT_STRU  m_Variant;

	public:
		static const char* GetValueTypeString(ckValueType type);
		static ckValueType	Parse(const char* szType);
	};
}


#endif //__CK_VALUE_H__
